import {createRouter, createWebHistory} from 'vue-router'
import Layout from '../layout/Layout.vue'

const routes = [
    {
        path: '/',
        name: 'Layout',
        component: Layout,
        redirect: "/home",
        children: [
            {   //  主页展示
                path: 'home',
                name: 'Home',
                component: () => import("@/views/Home"),
            },
            {   //  心理测试入口
                path: 'psychotest',
                name: 'PsychoTest',
                component: () => import("@/views/PsychoTest"),
            },
            {  //  我的心理测试结果
                path: 'mypsychotestres',
                name: 'MypsychotestRes',
                component: () => import("@/views/MypsychotestRes"),
            },
            {   //  心理访谈预约页面
                path: 'healthtalkorder',
                name: 'HealthTalkOrder',
                component: () => import("@/views/HealthTalkOrder"),
            },
            {   //  我的访谈记录页面
                path: 'mytalkrecord',
                name: 'MytalkRecord',
                component: () => import("@/views/MytalkRecord"),
            },
            {   //  我的咨询问卷
                path: 'quesnaire',
                name: 'QuesNaire',
                component: () => import("@/views/QuesNaire"),
            },
            {   //  心理咨询预约页面
                path: 'healthconsultorder',
                name: 'HealthConsultOrder',
                component: () => import("@/views/HealthConsultOrder"),
            },
            {   //  我的心理咨询记录页面
                path: 'myconsultrecord',
                name: 'MyconsultRecord',
                component: () => import("@/views/MyconsultRecord"),
            },
            {   //  危机上报页面
                path: 'dangersend',
                name: 'DangerSend',
                component: () => import("@/views/DangerSend"),
            },
            {   //  我的学生管理页面
                path: 'studentmanage',
                name: 'StudentManage',
                component: () => import("@/views/StudentManage"),
            },
            {   //  我的用户管理页面
                path: 'usersmanage',
                name: 'UsersManage',
                component: () => import("@/views/UsersManage")
            },
            {   //  重点学生库
                path: 'importstulib',
                name: 'ImportstuLib',
                component: () => import("@/views/ImportstuLib"),
            },
            {   //  表格上传
                path: 'excelupload',
                name: 'ExcelUpload',
                component: () => import("@/views/ExcelUpload"),
            },
            {   //  我的团体课程
                path: 'teamcourse',
                name: 'TeamCourse',
                component: () => import("@/views/TeamCourse")
            },
            {   //  我的个人中心
                path: 'personinfo',
                name: 'PersonInfo',
                component: () => import("@/views/PersonInfo")
            }
        ]
    },
    {   //  我的登录入口
        path: '/login',
        name: 'Login',
        component: () => import("@/views/Login")
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path === '/login') return next()
    const user = window.sessionStorage.getItem('user')
    if (!user) return next('/login')
    next()

})

export default router
